package cn.codingjc.nacos;

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;

import java.util.Properties;
import java.util.concurrent.TimeUnit;

/**
 * @author: Allen.qiu
 * @Date: 2022/7/16 23:33
 * @description:
 **/
public class RegisterNacosInstance {

    public static final String NACOS_SERVER = "192.168.239.131:8848";
    public static final String GROUP = "MICROCLOUD_GROUP";
    public static final String NAMESPACE = "a3575eaf-f53a-481a-807a-9277fe43e87f";
    public static final String INSTANCE_ID = "micro.provider.dept";

    public static void main(String[] args) throws Exception {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.SERVER_ADDR, NACOS_SERVER);
        properties.put(PropertyKeyConst.NAMESPACE, NAMESPACE);
        NamingService namingService = NamingFactory.createNamingService(properties);
        namingService.registerInstance(INSTANCE_ID, GROUP, "1.1.1.1", 8080, "deptCluster");
        // 持续向nacos发送心跳
        TimeUnit.MINUTES.sleep(Long.MAX_VALUE);
    }
}
